/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.controller.employee;

import com.entity.Employee;
import com.model.EmployeeModel;
import java.util.List;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Tuan Long
 */
@Named(value = "showEmployees")
@RequestScoped
public class ShowEmployees {

    /**
     * Creates a new instance of ShowEmployees
     */
    public ShowEmployees() {
    }

    private List<Employee> employees;
    EmployeeModel model = new EmployeeModel();

    public List<Employee> getEmployees() {

        employees = model.getAllEmployee();
        return employees;
    }

    private int eventId;
    private List<Employee> registers;

    public List<Employee> getRegisters() {
        HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        String text = req.getParameter("eventId");
        try {
            eventId = Integer.parseInt(text);
            if (eventId > 0) {
                registers = model.getRegisters(eventId);
            }
        } catch (NumberFormatException ex) {
            return registers;
        }
        return registers;
    }

    public int getEventId() {
        return eventId;
    }

    public void setEventId(int eventId) {
        this.eventId = eventId;
    }

}
